﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Configuration;
using System.ServiceModel.Web;
using System.IO;
using System.ServiceModel;
using System.Runtime.Serialization;

namespace Cleverscape.UTorrentClient.WebClient.ServiceDefinition
{
    [ServiceContract]
    public interface IUTorrentWebClient
    {
        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&list=1"

            )]
        IAsyncResult BeginGetAllTorrentsAndLabelsAndRSSAndFilters(string token, AsyncCallback callback, object state);
        TorrentsAndLabels EndGetAllTorrentsAndLabelsAndRSSAndFilters(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&list=1&cid={CacheID}"
            )]
        IAsyncResult BeginGetUpdatedTorrentsAndLabelsAndRSSAndFilters(string CacheID, string token, AsyncCallback callback, object state);
        UpdatedTorrentsAndLabels EndGetUpdatedTorrentsAndLabelsAndRSSAndFilters(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=getsettings"
            )]
        IAsyncResult BeginGetSettings(string token, AsyncCallback callback, object state);
        UTorrentSettings EndGetSettings(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=setsetting&s={SettingName}&v={SettingValue}"
            )]
        IAsyncResult BeginSetStringSetting(string SettingName, string SettingValue, string token, AsyncCallback callback, object state);
        GenericResponse EndSetStringSetting(IAsyncResult asyncResult);

        //[OperationContract(AsyncPattern = true)]
        //[WebGet(
        //    BodyStyle = WebMessageBodyStyle.Bare,
        //    ResponseFormat = WebMessageFormat.Json,
        //    UriTemplate = "/?token={token}&action=setsetting&s={SettingName}&v={SettingValue}"
        //    )]
        //IAsyncResult BeginSetBooleanSetting(string SettingName, string SettingValue, string token, AsyncCallback callback, object state);
        //GenericResponse EndSetBooleanSetting(IAsyncResult asyncResult);

        //[OperationContract(AsyncPattern = true)]
        //[WebGet(
        //    BodyStyle = WebMessageBodyStyle.Bare,
        //    ResponseFormat = WebMessageFormat.Json,
        //    UriTemplate = "/?token={token}&action=setsetting&s={SettingName}&v={SettingValue}"
        //    )]
        //IAsyncResult BeginSetIntegerSetting(string SettingName, int SettingValue, string token, AsyncCallback callback, object state);
        //GenericResponse EndSetIntegerSetting(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=getfiles&hash={TorrentHash}"
            )]
        IAsyncResult BeginGetFiles(string TorrentHash, string token, AsyncCallback callback, object state);
        TorrentFiles EndGetFiles(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=getprops&hash={TorrentHash}"
            )]
        IAsyncResult BeginGetProperties(string TorrentHash, string token, AsyncCallback callback, object state);
        TorrentProperties EndGetProperties(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=setprops&hash={TorrentHash}&s={PropertyName}&v={PropertyValue}"
            )]
        IAsyncResult BeginSetStringProperty(string TorrentHash, string PropertyName, string PropertyValue, string token, AsyncCallback callback, object state);
        GenericResponse EndSetStringProperty(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=setprops&hash={TorrentHash}&s={PropertyName}&v={PropertyValue}"
            )]
        IAsyncResult BeginSetIntegerProperty(string TorrentHash, string PropertyName, int PropertyValue, string token, AsyncCallback callback, object state);
        GenericResponse EndSetIntegerProperty(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=setprops&hash={TorrentHash}&s={PropertyName}&v={PropertyValue}"
            )]
        IAsyncResult BeginSetLongProperty(string TorrentHash, string PropertyName, long PropertyValue, string token, AsyncCallback callback, object state);
        GenericResponse EndSetLongProperty(IAsyncResult asyncResult);


        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=start&hash={TorrentHash}"
            )]
        IAsyncResult BeginStartTorrent(string TorrentHash, string token, AsyncCallback callback, object state);
        GenericResponse EndStartTorrent(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=stop&hash={TorrentHash}"
            )]
        IAsyncResult BeginStopTorrent(string TorrentHash, string token, AsyncCallback callback, object state);
        GenericResponse EndStopTorrent(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=pause&hash={TorrentHash}"
            )]
        IAsyncResult BeginPauseTorrent(string TorrentHash, string token, AsyncCallback callback, object state);
        GenericResponse EndPauseTorrent(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=forcestart&hash={TorrentHash}"
            )]
        IAsyncResult BeginForceStartTorrent(string TorrentHash, string token, AsyncCallback callback, object state);
        GenericResponse EndForceStartTorrent(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=unpause&hash={TorrentHash}"
            )]
        IAsyncResult BeginUnPauseTorrent(string TorrentHash, string token, AsyncCallback callback, object state);
        GenericResponse EndUnPauseTorrent(IAsyncResult asyncResult);
        
        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=recheck&hash={TorrentHash}"
            )]
        IAsyncResult BeginRecheckTorrent(string TorrentHash, string token, AsyncCallback callback, object state);
        GenericResponse EndRecheckTorrent(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=remove&hash={TorrentHash}"
            )]
        IAsyncResult BeginRemoveTorrent(string TorrentHash, string token, AsyncCallback callback, object state);
        GenericResponse EndRemoveTorrent(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=rss-remove&feed-id={FeedId}"
            )]
        IAsyncResult BeginRemoveRss(int FeedId, string token, AsyncCallback callback, object state);
        GenericResponse EndRemoveRss(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=rss-update&feed-id={FeedId}&url={Url}&alias={Alias}&subscribe={Subscribe}&smart-filter={SmartFilter}&enabled={Enabled}&update={Update}"
            )]
        IAsyncResult BeginUpdateAddRss(int FeedId, string Url, string Alias, bool Subscribe, bool SmartFilter, bool Enabled, int Update, string token, AsyncCallback callback, object state);
        GenericResponse EndUpdateAddRss(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=filter-remove&filter-id={FilterId}"
            )]
        IAsyncResult BeginRemoveFilter(int FilterId, string token, AsyncCallback callback, object state);
        GenericResponse EndRemoveFilter(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=filter-update&filter-id={FilterId}&name={Name}&save-in={SaveIn}&episode={Episode}&filter={Filter}&not-filter={NotFilter}&label={Label}&quality={Quality}&episode-filter={EpisodeFilter}&origname={OrigName}&prio={Prio}&smart-ep-filter={SmartEpFilter}&add-stopped={AddStopped}&postpone-mode={PostponeMode}&feed-id={FeedId}"
            )]
        IAsyncResult BeginUpdateAddFilter(int FilterId, string Name, string SaveIn, string Episode, string Filter, string NotFilter, string Label, int Quality, bool EpisodeFilter, bool OrigName, bool Prio, bool SmartEpFilter, bool AddStopped, int PostponeMode, int FeedId, string token, AsyncCallback callback, object state);
        GenericResponse EndUpdateAddFilter(IAsyncResult asyncResult);


        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=removedata&hash={TorrentHash}"
            )]
        IAsyncResult BeginRemoveTorrentAndData(string TorrentHash, string token, AsyncCallback callback, object state);
        GenericResponse EndRemoveTorrentAndData(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=setprio&hash={TorrentHash}&p={Priority}&f={FileNumber}"
            )]
        IAsyncResult BeginSetFilePriority(string TorrentHash, int FileNumber, int Priority, string token, AsyncCallback callback, object state);
        GenericResponse EndSetFilePriority(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/?token={token}&action=add-url&s={TorrentUrl}"
            )]
        IAsyncResult BeginAddTorrentFromUrl(string TorrentUrl, string token, AsyncCallback callback, object state);
        GenericResponse EndAddTorrentFromUrl(IAsyncResult asyncResult);

        [OperationContract(AsyncPattern = true)]
        [WebGet(
			//BodyStyle = WebMessageBodyStyle.Bare,
			UriTemplate = "/token.html"
			)]
        IAsyncResult BegingetToken(AsyncCallback callback, object state);
        string EndgetToken(IAsyncResult asyncResult);

    }
    [DataContract]
    public class ImageUpload
    {
        [DataMember]
        public string FileName;
        [DataMember]
        public byte[] Image;
    }


}
